#include "ShaderManager.h"
#include <iostream>

ShaderManager::ShaderManager()
{
	glewInit();
}

bool ShaderManager::GPUSupportsShaders()
{
	return (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader);
}

bool ShaderManager::LoadShader(const std::string& Vert, const std::string& Frag, const std::string& Tag)
{
	if(GPUSupportsShaders())
	{
		auto it = m_ShaderMap.find(Tag);
		if(it == m_ShaderMap.end())
		{
			GLShader TempShader;
			TempShader.Load(Vert, Frag);
			m_ShaderMap[Tag] = TempShader;
			return true;
		}
		else
		{
			std::cout << "Shader " << Tag << " Already exists\n";
			return false;
		}
	}
	return false;
}

void ShaderManager::UseShader(const std::string& Tag)
{
	auto it = m_ShaderMap.find(Tag);
	if(it != m_ShaderMap.end())
	{
		m_ShaderMap[Tag].UseThisShader();
	}
	else
	{
		std::cout << "Shader " << Tag << " does not exits\n";
	}
}

void ShaderManager::UnBind()
{
	glUseProgram(NULL);
}

